<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props 函数式组件限制属性值的类型</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <!-- 1. 引入 prop 文件 -->
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
        //外部数据
        let obj = {
            name: '桃子',
            gender: '女',
            jiaxiang: '石家庄'
        }


        //函数式组件声明  2. 在函数里接收一个参数
        function Student(props){
            //3. 解构 获取数据
            let {name, age, gender} = props;
            return <div>
                    <ul>
                        <li>姓名: {name}</li>    
                        <li>年龄: {age}</li>    
                        <li>性别: {gender}</li>    
                    </ul>
                    <hr />
                </div>
        }

        //2. 声明函数对象属性
        Student.propTypes = {
            name: PropTypes.string.isRequired,
            age: PropTypes.number,
            gender: PropTypes.string
        }

        Student.defaultProps = {
            age: 19
        }

        //升级简化
        ReactDOM.render(<Student  {...obj}  />, document.querySelector('#root'));


    </script>
</body>
</html>